package com.example.mvpdemo.simple2;

/**
 * p层
 * 特点一：持有M层引用
 * 特点二：持有V层引用
 * 特点三：对M层和V层进行关联
 */
public class WeatherPresenter_2 {

    private WeatherModel_2 weatherModel;
    private WeatherView_2 weatherView;

    public WeatherPresenter_2(WeatherView_2 weatherview) {
        this.weatherModel = new WeatherModel_2();
        this.weatherView = weatherview;
    }

    public void attachView(WeatherView_2 weatherview) {
        this.weatherView = weatherview;
    }

    public void detachView() {
        this.weatherView = null;
    }

    public void weeather(String cityname) {

        this.weatherModel.weather(cityname, new WeatherModel_2.onResult() {
            @Override
            public void success(String result) {
                if (weatherView != null)
                    weatherView.onWeatherGetSuccess(result);
            }

            @Override
            public void fail(String result) {
                if (weatherView != null)
                    weatherView.onWeatherGetFail(result);
            }
        });
    }

}
